const Router = require('koa-router');

//设置 一级 路由名 prefix ——> /user
// http://localhost:15432/user/
const router = new Router({ prefix: '/user' });

//中间件 
const { userValidator, verifyUser, crpytPassword, comparePassword } = require('../middleware/user.middleware')

const { auth } = require('../middleware/auth.middleware')

const { register, login, changePassword } = require('../controller/user.controller')

//GET user
// router.get('/', async (ctx, next) => {
//     ctx.body = 'user';
// });

//POST 
// 注册接口 合法性 合理性 加盐 register
router.post('/register', userValidator, verifyUser, crpytPassword, register)

// 登录接口
router.post('/login', userValidator, comparePassword, login)

// 修改密码接口 patch修改某字段
router.patch('/setPassword', auth, crpytPassword, changePassword)

module.exports = router;